﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Projekt.Models;

namespace Projekt.Actors
{
    public static class Player
    {
        static Engine game;
        static CustomModel model;
        static public CustomModel Model
        {
            get { return model; }
        }

        private static double aMax = 5;
        public static double AMax
        {
            get { return Player.aMax; }
            set { Player.aMax = value; }
        }

        private static double aCurrent = 0;
        public static double ACurrent
        {
            get { return Player.aCurrent; }
            set { Player.aCurrent = value; }
        }

        public static void Initialize(CustomModel _model, Engine _game)
        {
            game = _game;
            model = _model;
        }

        public static void Update(GameTime gameTime)
        {
            KeyboardState keyState = Keyboard.GetState();

            Vector3 rotChange = new Vector3(0, 0, 0);

            // Determine on which axes the ship should be rotated on, if any
            //if (keyState.IsKeyDown(Keys.Down))
            //    rotChange += new Vector3(1, 0, 0);
            //if (keyState.IsKeyDown(Keys.Up))
            //    rotChange += new Vector3(-1, 0, 0);
            if (keyState.IsKeyDown(Keys.Left))
                rotChange += new Vector3(0, 1, 0);
            if (keyState.IsKeyDown(Keys.Right))
                rotChange += new Vector3(0, -1, 0);

            game.models[0].Rotation += rotChange * .025f;

            // If space isn't down, the ship shouldn't move
            if (!keyState.IsKeyDown(Keys.Up))
            {
                if(ACurrent >= 0) ACurrent -= 0.1d;
            }
            else
                if (ACurrent <= AMax) ACurrent += 0.1d;

            if (ACurrent > 0)
            {
                // Determine what direction to move in
                Matrix rotation = Matrix.CreateFromYawPitchRoll(model.Rotation.Y, model.Rotation.X, model.Rotation.Z);

                // Move inthe direction dictated by our rotation matrix
                model.Position += Vector3.Transform(Vector3.Forward, rotation) * (float)gameTime.ElapsedGameTime.TotalMilliseconds * (float)ACurrent;
            }
        }
    }
}
